package com.yc.tomcat.impl;

import com.yc.tomcat.Cookie;

public class CookieImpl implements Cookie {
    private String name;
    private String value;
    private String domain;
    private Integer maxAge;
    private String path;

    public CookieImpl(String name, String value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public String toString() {
       String res = name + "=" + value;
       if(maxAge!=null){
           res += "; Max-Age=" + maxAge;
       }
        if(path!=null){
            res += "; Path=" + path;
        }
        if(domain!=null){
            res += "; Domain=" + domain;
        }
        res += "\n";
        return res;
    }

    @Override
    public void setDomain(String pattern) {
        this.domain = pattern;
    }

    @Override
    public void setMaxAge(int expiry) {
        this.maxAge = expiry;
    }

    @Override
    public void setPath(String uri) {
        this.path = uri;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getValue() {
        return value;
    }
}
